package com.engine.modules.ytht.mapper;

import com.engine.modules.ytht.entity.ContractEntity;
import com.engine.modules.ytht.entity.FarmersFieldsEntity;
import com.engine.modules.ytht.entity.LocationEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author HX
 * @version 1.0.0
 * @ClassName ContractMapper.java
 * @Description TODO
 * @createTime 2022年2月16日
 */
@Repository
@Slf4j
public class ContractMapper {

    @Autowired
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    public List<ContractEntity> getContractByFieldBlockId(String fbId) {
        Map<String, Object> map = new HashMap<>();
        map.put("field_id", fbId);
        String sql="SELECT year FROM r_famers_fields WHERE id_card=:id_card AND field_id=:field_id AND year=:year";
        List<Map<String, Object>> year2= namedParameterJdbcTemplate.queryForList(sql,map);
        sql = "INSERT INTO r_famers_fields(id,id_card,field_id,year,gmt_create,gmt_update,del_flag)" +
                "VALUES (uuid_generate_v4(),:id_card,:field_id,:year,NOW(),NOW(),'0')";
        List<ContractEntity> contractEntityList =namedParameterJdbcTemplate.query(sql, map, new RowMapper<ContractEntity>() {
            @Override
            public ContractEntity mapRow(ResultSet resultSet, int i) throws SQLException {
                return null;
            }
        });
        return contractEntityList;
    }
}
